package com.example.mapper;

import com.example.pojo.Emp;
import com.example.pojo.EmpQueryParam;
import com.example.pojo.GenderCount;
import com.example.pojo.PageResult;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * EmpMapper 类的描述信息
 *
 * @author 12427
 * @since 2025/6/4 17:15
 */
@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数  ----------原始分页
     */
//    @Select(" SELECT count(*) FROM emp e LEFT JOIN dept d on e.dept_id=d.id")
//    public Long count();
//    /**
//     * 查询 每页数量
//     */
//    @Select("SELECT e.*,d.name as deptName FROM emp e LEFT JOIN dept d on e.dept_id=d.id order by e.update_time desc " +
//            "LIMIT #{start},#{pageSize}")
//    public List<Emp> list(Integer start, Integer pageSize);
//
    /**
     *   分页查询 pagehapler插件
     * */
//    @Select("SELECT e.*,d.name as deptName FROM emp e LEFT JOIN dept d on e.dept_id=d.id order by e.update_time desc " )

//    配置了xml
//    List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    /***/
//    新优化
    List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 添加员工
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")// 获取生成的主键
    @Insert("insert into emp (username, name, gender, phone, job, salary, image, entry_date, dept_id,create_time,update_time) VALUEs" +
            "(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 批量删除员工
     */
    void deleteById(List<Integer> ids);

    Emp getById(Integer id);

    /**
     * 根据id跟新员工信息
     */
    void updateById(Emp emp);


    /**
     * 查询 各个 职位人数
     */
    @MapKey("pos")//要指定Key
    public List<Map<String, Object>> countEmpJobData();

    @MapKey("name")
    List<Map<String, Object>> getEmpGender();
@Select("select * from emp where username=#{username} and password=#{password}")
    Emp selectByusenamePs(Emp emp);


//    List<GenderCount> getEmpGender();//这是封装到自定义对象中
    /***/
}
